package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.AdviceMapper;
import com._51cto.healthy.pojo.Advice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class AdviceServiceImpl implements AdviceService{
   @Autowired
    private AdviceMapper adviceMapper;
    @Override
    public BaseMapper<Advice> getDao() {
        return adviceMapper;
    }

    @Override
    public P<Advice> findAll(String query, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Advice> all =adviceMapper.findAll(query);
        PageInfo<Advice> pageInfo = new PageInfo<>(all);

        return new P<Advice>().setPageNum(pageInfo.getPageNum())
                .setRows(pageInfo.getList())
                .setTotal(pageInfo.getTotal())
                .setPageSize(pageInfo.getPageSize())
                .setPages(pageInfo.getPages());
    }

    @Override
    public void deleteByPK(Integer pk) {
        AdviceService.super.deleteByPK(pk);
    }

    @Override
    public void update(Advice entity) {
        AdviceService.super.update(entity);
    }

    @Override
    public void insert(Advice entity) {
        AdviceService.super.insert(entity);
    }
}
